package com.xiekong.rpc.server;

import com.xiekong.rpc.registry.ServiceRegistry;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * Netty RPC服务器
 *
 * @author XieKong
 */
public abstract class RpcServer {
    private String serviceAddress;
    private ServiceRegistry serviceRegistry;
    /**
     * 存放服务名与服务对象之间的映射关系
     */
    private Map<String, Object> serviceMap;

    public RpcServer(String serviceAddress, ServiceRegistry serviceRegistry) {
        if (StringUtils.isEmpty(serviceAddress)) {
            throw new IllegalArgumentException("服务地址为空");
        }
        if (serviceRegistry == null) {
            throw new IllegalArgumentException("注册服务为空");
        }
        this.serviceAddress = serviceAddress;
        this.serviceRegistry = serviceRegistry;
    }

    public abstract void startup();

    public String getServiceAddress() {
        return serviceAddress;
    }

    public void setServiceAddress(String serviceAddress) {
        this.serviceAddress = serviceAddress;
    }

    public ServiceRegistry getServiceRegistry() {
        return serviceRegistry;
    }

    public void setServiceRegistry(ServiceRegistry serviceRegistry) {
        this.serviceRegistry = serviceRegistry;
    }

    public Map<String, Object> getServiceMap() {
        return serviceMap;
    }

    public void setServiceMap(Map<String, Object> serviceMap) {
        this.serviceMap = serviceMap;
    }
}
